import {getContainerSources, getStorageSources} from "./public/CreepPublicAction.js";

export const scouterRun = (creep,sourcesIndex) => {
    // workSwitch(creep, '🔄 harvest', '⚡ upgrade')
    // if (creep.memory[WORKSTATE]) {
    //     workCore(creep)
    // } else {
    //     getSources(creep)
    // }
    workCore(creep)
}

const workCore = (creep) => {
    const currentRoom = 'E43N24'; // 当前房间
    const targetRoom = 'E43N25'; // 目标房间

// 确保路径是正确的
    const route = Game.map.findRoute(currentRoom, targetRoom);

    if (route.length > 0) {
        const nextStep = route[0]; // 路线中的第一步

        if (creep.room.name === currentRoom) {
            // 如果爬虫还在当前房间，移动到出口
            const exit = creep.room.find(nextStep.exit);
            creep.moveTo(exit[0]);
        } else if (creep.room.name === targetRoom) {
            // 如果爬虫已经在目标房间，指示它该怎么做
            const controller = creep.room.controller;
            if (controller && !controller.my) {
                creep.moveTo(controller);
                creep.claimController(controller);
            }
        } else {
            // 如果爬虫不在任何已知房间
            console.log('爬虫在未知房间');
        }
    } else {
        console.log('找不到通往目标房间的路线');
    }

}

const getSources = (creep,sourcesIndex) => {
    if (!getStorageSources(creep, sourcesIndex, '#d9c8ec')) {
        getContainerSources(creep, sourcesIndex, '#d9c8ec')
    }
}